package com.atguigu.spzx.product.controller;

import com.atguigu.spzx.model.entity.product.Category;
import com.atguigu.spzx.model.entity.product.ProductSku;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.atguigu.spzx.model.vo.h5.IndexVo;
import com.atguigu.spzx.model.vo.h5.ProductItemVo;
import com.atguigu.spzx.product.service.CategoryService;
import com.atguigu.spzx.product.service.ProductSkuService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.simpleframework.xml.Path;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: IndexController
 * Package: com.atguigu.spzx.product.controller
 * Description:
 *
 * @Author 刘强
 * @Create 2024/7/14 12:44
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/product/index")
//@CrossOrigin
public class IndexController {
    @Resource
    private CategoryService categoryService;
    @Resource
    private ProductSkuService productSkuService;



    /**
     * 查询首页需要的商品数据
     *
     * @return
     */
    @GetMapping
    public Result<IndexVo> findData() {
        List<Category> categoryList = categoryService.findOneCategory();
        List<ProductSku> productSkuList = productSkuService.findProductSkuBySale();
        IndexVo indexVo = new IndexVo();
        indexVo.setCategoryList(categoryList);
        indexVo.setProductSkuList(productSkuList);
        return Result.build(indexVo, ResultCodeEnum.SUCCESS);
    }
}
